import 'package:flutter/material.dart';

import 'package:flutter_demo/widgets/groupSlotWidget.dart';
import 'package:flutter_demo/widgets/groupHeaderWidget.dart';
import 'package:flutter_demo/widgets/textWidget.dart';

import 'package:flutter_demo/models/features.dart';

class MFeatures extends StatelessWidget {
  final title;
  final Features features;

  MFeatures({
    this.title = "特色品牌",
    @required this.features,
  }) : assert(features != null);

  @override
  Widget build(BuildContext context) {
    return MGroupSlot(
      padding: 0.0,
      header: MGroupHeader(title),
      body: MFeaturesWidget(features),
      footer: Padding(
        padding: const EdgeInsets.all(10.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[MText("更多品牌 >")],
        ),
      ),
    );
  }
}

class MFeaturesWidget extends StatelessWidget {
  final Features features;
  MFeaturesWidget(this.features);

  @override
  Widget build(BuildContext context) {
    double _padding = 10.0;

    double _screenWidth = MediaQuery.of(context).size.width;
    double _imageWidth1 = (_screenWidth - _padding * 3) * 0.675;
    double _imageWidth2 = (_imageWidth1 - _padding) / 2.0;

    return Container(
      color: Colors.brown[200],
      child: Padding(
        padding: EdgeInsets.all(_padding),
        child: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                DecoratedBox(
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(100.0),
                  ),
                  child: Image.network(
                    features.imageBrand,
                    width: 50.0,
                    height: 50.0,
                  ),
                ),
                Padding(
                  padding: EdgeInsets.only(left: 8.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      MText(features.title,
                          color: Colors.white, fontSize: 16.0),
                      MText(features.detail,
                          color: Colors.white, fontSize: 12.0),
                    ],
                  ),
                ),
              ],
            ),
            SizedBox(height: _padding),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Image.network(
                  features.imageScr1,
                  width: _imageWidth1,
                  height: _imageWidth1,
                ),
                Column(
                  children: <Widget>[
                    Image.network(
                      features.imageScr2,
                      width: _imageWidth2,
                      height: _imageWidth2,
                    ),
                    SizedBox(height: _padding),
                    Image.network(
                      features.imageScr3,
                      width: _imageWidth2,
                      height: _imageWidth2,
                    ),
                  ],
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
